package com.waidi.clothespad.fragment;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DownloadManager;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.Html;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ScaleXSpan;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.waidi.clothespad.R;
import com.waidi.clothespad.adapter.BaseInfoAdapter;
import com.waidi.clothespad.adapter.DuoXuanAdapter;
import com.waidi.clothespad.adapter.ListviewData;
import com.waidi.clothespad.adapter.MyListViewAdapter;
import com.waidi.clothespad.common.ChangXianProductNum;
import com.waidi.clothespad.common.Config;
import com.waidi.clothespad.common.Db;
import com.waidi.clothespad.common.DpsOrderInfo;
import com.waidi.clothespad.common.FaultInfo;
import com.waidi.clothespad.common.IcMesOrderProcessRouteMapInfo;
import com.waidi.clothespad.common.MessageToUi;
import com.waidi.clothespad.common.MyToast;
import com.waidi.clothespad.common.Qccxzjlxt;
import com.waidi.clothespad.mqttclient.MyMqttClient;
import com.waidi.clothespad.ui.WaitDialog;


import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Administrator on 2017/4/26.
 */

public class FragShenglineqc extends Fragment {
    private static final String TAG = FragShenglineqc.class.getName();

    @BindView(R.id.fault_commit_bt)
    Button fault_bt;

    @BindView(R.id.pd_order_id)
    TextSwitcher pd_order_id;

    @BindView(R.id.pd_style_id)
    TextSwitcher pd_style_value;

    @BindView(R.id.pd_order_number)
    TextSwitcher pd_order_number_value;

    @BindView(R.id.pd_hanger_id)
    TextSwitcher pd_hanger_id_value;


    @BindView(R.id.order_finished_num)
    TextSwitcher tV_order_finished_num;


    @BindView(R.id.order_defect_num)
    TextSwitcher tV_order_defect_num;

    @BindView(R.id.day_finished_num)
    TextSwitcher tV_day_finished_num;

    @BindView(R.id.day_defect_num)
    TextSwitcher tV_day_defect_num;



    Unbinder unbinder;
    private View view;
    public Context context;
    private Db myDbHelper =null;
    public Gyinfo handler =null;

    public boolean get_ok = false;


    PopupWindow popupWindow;
    LayoutInflater inflater;
    private List<Map<String, Object>> dataList;
    private SimpleAdapter adapter;
    private GridView gridView2;
    private PullToRefreshGridView gridview = null;
    private ListView listView;
    private TextView tv;
    private Button bt;
    public BaseInfoAdapter myadapter=null;
    public DuoXuanAdapter duoxuanadapter = null;

    private MyListViewAdapter mAdapter = null;
    private List<ListviewData> mData = null;
    private WaitDialog waitDialog =null;
    public boolean onDetach = false;

    public static int rtlcode0= 0;
    public static String key0= "";
    public static int rtlcode1= 0;


    public static String LastProcessLineCache;
    public static String LastProductCache;


    private AnimationSet InAnimationSet;
    private AnimationSet OutAnimationSet;



    private AnimationSet InAnimationSet1;
    private AnimationSet OutAnimationSet1;


    private AnimationSet InAnimationSet2;
    private AnimationSet OutAnimationSet2;


    private AnimationSet InAnimationSet3;
    private AnimationSet OutAnimationSet3;


    private AnimationSet InAnimationSet4;
    private AnimationSet OutAnimationSet4;


    private AnimationSet InAnimationSet5;
    private AnimationSet OutAnimationSet5;

    private AnimationSet InAnimationSet6;
    private AnimationSet OutAnimationSet6;


    private AnimationSet InAnimationSet7;
    private AnimationSet OutAnimationSet7;

    /**
     * 用了存放点击的gridview的item的pos和这个pos的选中状态
     */
    private Map<Integer,Boolean> gvChooseMap = new HashMap<Integer, Boolean>();


    public FragShenglineqc()
    {
        handler = new Gyinfo();
    }



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.frag_product_line_qc, container, false);
        unbinder = ButterKnife.bind(this, view);
        onDetach = false;
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();

        //getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        //initParam();
        //initElem();
        LastProductCache = "";
        LastProcessLineCache="";


        listView = (ListView) view.findViewById(R.id.list_process_sheet);
        gridview = (PullToRefreshGridView)view.findViewById(R.id.gridview);


     /*   GridView refreshableView = gridview.getRefreshableView();
        refreshableView.setNumColumns(4);*/


        List<String> name = new ArrayList();
        name.add("101");
        duoxuanadapter = new DuoXuanAdapter(context,name);

        gridview.setAdapter(duoxuanadapter);
        duoxuanadapter.notifyDataSetChanged();

// gridview的item的点击事件  OnItemClickListener
/*        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.i("onItemClick", Integer.toString(position));
               // Toast.makeText(context, Integer.toString(position), Toast.LENGTH_LONG).show();
                myadapter.setSeclection(position);
                myadapter.notifyDataSetChanged();
            }
        });*/

        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int pos,
                                    long arg3) {
                if(view.isActivated()){
                    view.setActivated(false);
                   // gvChooseMap.put(pos, false);
                }else{
                    view.setActivated(true);
                  //  gvChooseMap.put(pos, true);
                }
                duoxuanadapter.notifyDataSetChanged();
            }
        });

        gridview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<GridView>() {

            @Override
            public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {

               // String url = "http://" + Config.devConfig.web_addr + "/js/a/its/terminal/faultInfo?";
                Config A = new Config(context);
                Config.DpsInterface dpsInterface = A.new DpsInterface(Config.devConfig.web_addr);
                String url = dpsInterface.faultinfoget;

                sendRequestDefect(url);
                new FragShenglineqc.GetDataTask().execute();
            }
            @Override
            public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {
                //  Toast.makeText(context, "Pull Up!", Toast.LENGTH_SHORT).show();
                new FragShenglineqc.GetDataTask().execute();
            }
        });
        initData();
        timer.schedule(task,1000,15000); //定时获取工艺路线图
        new MessageToUi().send(200,"","",handler);

        fault_bt.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                try
                {
                /* Config.globalrealhangerid = "100";
                    key0 = "b49d4bc9-6393-4cd9-ab9f-fc3966a6aa7a";
                    httpUpdateQcResultV2 thread1 = new httpUpdateQcResultV2
                            (handler,context,"",key0,Config.globalrealhangerid,Config.RePairCodeString);
                    thread1.start();
                */

                    int fault_num = duoxuanadapter.getSelectNum();
                    if(fault_num<=0)
                    {
                        MyToast.showToast(context,"未选择返修原因！");
                        return;
                    }

                    if(mAdapter.map1.size()<=0)
                    {
                        MyToast.showToast(context,"返修工序未选择！");
                        return;
                    }
                    if(Config.globalrealhangerid.length()==0)
                    {
                        MyToast.showToast(context,"返修衣架为空！");
                        return;
                    }
                    else if(MyMqttClient.myClientConn==false)
                    //mqtt服务未连接的时候，不进行同步
                    {
                        MyToast.showToast(context,"mqtt服务未连接,无法进行返修，请尝试检查网络!");
                        return;
                    }
                    else
                    {
                        //多选工序编码
                        Config.RePairCodeString="";
                        for (MyListViewAdapter.CodeCheck value : mAdapter.map1.values())
                        {
                            Log.i(TAG,"Value = " + value.code);
                            Config.RePairCodeString =Config.RePairCodeString+value.code+""+";";
                        }
                        showReturnAlterDialog("确定需要返修衣架:      "+Config.globalrealhangerid,1);
                        //showAlertDialog("确定需要返修衣架:      "+Config.globalrealhangerid,1);
                     }
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        });


    }
    public void clear_listview_checked()
    {

        mAdapter.map1.clear();

    }

    public void create_animation()
    {
        AlphaAnimation alphaAnimation;
        TranslateAnimation translateAnimation;
        InAnimationSet = new AnimationSet(true);
        OutAnimationSet = new AnimationSet(true);


        InAnimationSet1 = new AnimationSet(true);
        OutAnimationSet1 = new AnimationSet(true);

        InAnimationSet2 = new AnimationSet(true);
        OutAnimationSet2 = new AnimationSet(true);

        InAnimationSet3 = new AnimationSet(true);
        OutAnimationSet3 = new AnimationSet(true);

        InAnimationSet4 = new AnimationSet(true);
        OutAnimationSet4 = new AnimationSet(true);

        InAnimationSet5 = new AnimationSet(true);
        OutAnimationSet5 = new AnimationSet(true);

        InAnimationSet6 = new AnimationSet(true);
        OutAnimationSet6 = new AnimationSet(true);


        InAnimationSet7 = new AnimationSet(true);
        OutAnimationSet7 = new AnimationSet(true);



        pd_order_id.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });

        pd_style_value.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });

        pd_order_number_value.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                return new TextView(context);
            }
        });
        pd_hanger_id_value.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView tv = new TextView(context);
                tv.setText("00000000");
                tv.setTextSize(22);
                TextPaint tp = tv .getPaint();
                tp.setFakeBoldText(true);
                tv.setGravity(Gravity.CENTER);
                tv.setTextColor(Color.parseColor("#FFFF0000"));
                return tv;
            }
        });



        tV_order_finished_num.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView tv = new TextView(context);
                tv.setText("0");
                tv.setTextSize(20);
                TextPaint tp = tv .getPaint();
                tp.setFakeBoldText(true);
                tv.setGravity(Gravity.CENTER);
                tv.setTextColor(Color.parseColor("#FF5ED5D1"));
                return tv;
            }
        });

        tV_order_defect_num.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView tv = new TextView(context);
                tv.setText("0");
                tv.setTextSize(20);
                TextPaint tp = tv .getPaint();
                tp.setFakeBoldText(true);
                tv.setGravity(Gravity.CENTER);
                tv.setTextColor(Color.parseColor("#FFFF0000"));//red

                return tv;
            }
        });




        tV_day_finished_num.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {

                TextView tv = new TextView(context);
                tv.setText("0");
                tv.setTextSize(20);
                TextPaint tp = tv .getPaint();
                tp.setFakeBoldText(true);
                tv.setGravity(Gravity.CENTER);
                tv.setTextColor(Color.parseColor("#FF5ED5D1"));
                return tv;
               // return new TextView(context);
            }
        });


        tV_day_defect_num.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public View makeView() {
                TextView tv = new TextView(context);
                tv.setText("0");
                tv.setTextSize(20);
                TextPaint tp = tv .getPaint();
                tp.setFakeBoldText(true);
                tv.setGravity(Gravity.CENTER);
                tv.setTextColor(Color.parseColor("#FFFF0000"));//red
                return tv;
            }
        });




        int h = pd_order_id.getHeight();
        if (h <= 0) {
            pd_order_id.measure(0,0);
            h = pd_order_id.getMeasuredHeight();
        }

/*        int h1 = pd_order_finished_number.getHeight();
        if (h1 <= 0) {
            pd_order_finished_number.measure(0,0);
            h1 = pd_order_finished_number.getMeasuredHeight();
        }


        int h2 = today_finshed_num.getHeight();
        if (h2 <= 0) {
            today_finshed_num.measure(0,0);
            h2 = today_finshed_num.getMeasuredHeight();
        }

        int h3 = today_bad_num.getHeight();
        if (h3 <= 0) {
            today_bad_num.measure(0,0);
            h3 = today_bad_num.getMeasuredHeight();
        }

        int h4 = today_ok_rate.getHeight();
        if (h4 <= 0) {
            today_ok_rate.measure(0,0);
            h4 = today_ok_rate.getMeasuredHeight();
        }*/



        alphaAnimation = new AlphaAnimation(0,1);
        translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
                Animation.ABSOLUTE, h, Animation.ABSOLUTE, 0);
        InAnimationSet.addAnimation(alphaAnimation);
        InAnimationSet.addAnimation(translateAnimation);
        InAnimationSet.setDuration(1000);


        InAnimationSet1.addAnimation(alphaAnimation);
        InAnimationSet1.addAnimation(translateAnimation);
        InAnimationSet1.setDuration(1000);


        InAnimationSet2.addAnimation(alphaAnimation);
        InAnimationSet2.addAnimation(translateAnimation);
        InAnimationSet2.setDuration(1000);


        InAnimationSet3.addAnimation(alphaAnimation);
        InAnimationSet3.addAnimation(translateAnimation);
        InAnimationSet3.setDuration(1000);

        InAnimationSet4.addAnimation(alphaAnimation);
        InAnimationSet4.addAnimation(translateAnimation);
        InAnimationSet4.setDuration(1000);


        InAnimationSet5.addAnimation(alphaAnimation);
        InAnimationSet5.addAnimation(translateAnimation);
        InAnimationSet5.setDuration(1000);

        InAnimationSet6.addAnimation(alphaAnimation);
        InAnimationSet6.addAnimation(translateAnimation);
        InAnimationSet6.setDuration(1000);

        InAnimationSet7.addAnimation(alphaAnimation);
        InAnimationSet7.addAnimation(translateAnimation);
        InAnimationSet7.setDuration(1000);



        alphaAnimation = new AlphaAnimation(1,0);
        translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0,
                Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -h);
        OutAnimationSet.addAnimation(alphaAnimation);
        OutAnimationSet.addAnimation(translateAnimation);
        OutAnimationSet.setDuration(1000);



        OutAnimationSet1.addAnimation(alphaAnimation);
        OutAnimationSet1.addAnimation(translateAnimation);
        OutAnimationSet1.setDuration(1000);



        OutAnimationSet2.addAnimation(alphaAnimation);
        OutAnimationSet2.addAnimation(translateAnimation);
        OutAnimationSet2.setDuration(1000);


        OutAnimationSet3.addAnimation(alphaAnimation);
        OutAnimationSet3.addAnimation(translateAnimation);
        OutAnimationSet3.setDuration(1000);


        OutAnimationSet4.addAnimation(alphaAnimation);
        OutAnimationSet4.addAnimation(translateAnimation);
        OutAnimationSet4.setDuration(1000);


        OutAnimationSet5.addAnimation(alphaAnimation);
        OutAnimationSet5.addAnimation(translateAnimation);
        OutAnimationSet5.setDuration(1000);

        OutAnimationSet6.addAnimation(alphaAnimation);
        OutAnimationSet6.addAnimation(translateAnimation);
        OutAnimationSet6.setDuration(1000);

        OutAnimationSet7.addAnimation(alphaAnimation);
        OutAnimationSet7.addAnimation(translateAnimation);
        OutAnimationSet7.setDuration(1000);

    }

    private void initWaitDialog()
    {
        waitDialog = new WaitDialog(context);
        waitDialog.setText("正在提交...");
    }

    void initData()
    {
        create_animation();
        initWaitDialog();
        mData = new LinkedList<ListviewData>();

/*        ListviewData list0 = new ListviewData(R.mipmap.worker,"工位 01","挂片-01","452");
        ListviewData list1 = new ListviewData(R.mipmap.worker,"工位 02","领圈、袖笼、肩缝、后中、叉、里拉链底粘籿-02","453");
        ListviewData list2 = new ListviewData(R.mipmap.worker,"工位 03","整件面里布烫缩-03","454");
        ListviewData list3 = new ListviewData(R.mipmap.worker,"工位 04","画胸垫位-04","452");
        ListviewData list4 = new ListviewData(R.mipmap.worker,"工位 05","套拉链里布-05","453");
        ListviewData list5 = new ListviewData(R.mipmap.worker,"工位 06","烫拉链-06","454");

        ListviewData list6 = new ListviewData(R.mipmap.worker,"工位 07","拼里布公主缝*2-07","460");
        ListviewData list7 = new ListviewData(R.mipmap.worker,"工位 08","收里布后腰省*2-08","475");
        ListviewData list8 = new ListviewData(R.mipmap.worker,"工位 09","拼里布后中拉链缝-09","485");
        ListviewData list9 = new ListviewData(R.mipmap.worker,"工位 10","放洗唛-10","460");

        mData.add(list0);
        mData.add(list1);
        mData.add(list2);
        mData.add(list3);
        mData.add(list4);
        mData.add(list5);
        mData.add(list6);
        mData.add(list7);

        mData.add(list8);
        mData.add(list9);*/

        mAdapter = new MyListViewAdapter((LinkedList<ListviewData>) mData,context);
        listView.setAdapter(mAdapter);

        pd_order_id.setText("");

        //TextView tv_style = (TextView)view.findViewById(R.id.pd_style_id);
        pd_style_value.setText("");

        //TextView tv_order_num = (TextView)view.findViewById(R.id.pd_order_number);
        pd_order_number_value.setText("");



      //  String defaultgylxt ="{\"action\":\"qc.info\",\"style_id\":\"AZQ1722-34-62\",\"style_size\":\"L\",\"style_colour\":\"黑色\",\"order_id\":\"D180517-0003\",\"order_quantity\":\"80\",\"data\":[{\"line_number\":\"1\",\"work_station\":\"1\",\"worker_id\":\"056\",\"worker_name\":\"朱香丽\",\"opera_desc\":\"锁边 将旗袍小肩线、侧缝线、底襟止口线、袖底缝用同类色线锁边\",\"opera_code\":\"669\",\"Primary_Order\":\"1\"},{\"line_number\":\"1\",\"work_station\":\"2\",\"worker_id\":\"056\",\"worker_name\":\"李小冉\",\"opera_desc\":\"打线钉 打线钉的部位有前、后片省位，臀围线\",\"opera_code\":\"666\",\"Primary_Order\":\"2\"},{\"line_number\":\"1\",\"work_station\":\"3\",\"worker_id\":\"056\",\"worker_name\":\"张荣京\",\"opera_desc\":\"开襟止点，腋下省，绱领点，后领中缝，袖山顶点，袖肘省\",\"opera_code\":\"666\",\"Primary_Order\":\"3\"},{\"line_number\":\"1\",\"work_station\":\"4\",\"worker_id\":\"056\",\"worker_name\":\"赵敏\",\"opera_desc\":\"缉省缝、扣烫\",\"opera_code\":\"666\",\"Primary_Order\":\"4\"},{\"line_number\":\"1\",\"work_station\":\"2\",\"worker_id\":\"056\",\"worker_name\":\"刘花儿\",\"opera_desc\":\"归拔后衣片。 拔开侧缝及中心线的腰部区域，并配合体型的要求拔出背部曲线\",\"opera_code\":\"666\",\"Primary_Order\":\"5\"},{\"line_number\":\"1\",\"work_station\":\"2\",\"worker_id\":\"056\",\"worker_name\":\"张大毛\",\"opera_desc\":\"将拉链的反面与后衣片的正面对齐，利用拉链专用压脚（隐形压脚）\",\"opera_code\":\"666\",\"Primary_Order\":\"6\"}]}";




/*        File gylxt = new File(Config.gylxttxt);
        if(!gylxt.exists())//暂时不使用
        {
            try {
                FileInputStream in = new FileInputStream(gylxt);
                int len = 0;
                byte[] buf = new byte[1024];
                String  strbuf;
                String  strjson="";
                while((len=in.read(buf))!=-1)
                {
                    strbuf = new String(buf,0,len);
                    strjson = strjson + strbuf;
                }
                in.close();
                if(strjson==null)
                    return;
                JSONObject jsonObj = new JSONObject(strjson);
                if(jsonObj==null)
                    return;
                String style_id = jsonObj.optString("style_id");
                String order_id = jsonObj.optString("order_id");
                String style_size = jsonObj.optString("style_size");
                String style_colour = jsonObj.optString("style_colour");
                String Order_Quantity = jsonObj.optString("order_quantity");

                Config.qccxzjlxt.order_id =order_id;
                Config.qccxzjlxt.style_id = style_id;
                Config.qccxzjlxt.order_quantity =Order_Quantity;
                Log.i(TAG,Config.qccxzjlxt.order_id+"-"+Config.qccxzjlxt.style_id+"-"+Config.qccxzjlxt.order_quantity);


                JSONArray qcArray = jsonObj.getJSONArray("data");
                if(qcArray==null)
                    return;

                Qccxzjlxt B = new Qccxzjlxt();
                if(qcArray.length()!=0)
                    Config.qccxzjlxt.gxinfoArrayList.clear();


                for (int i=0;i<qcArray.length();i++)
                {
                    JSONObject s= (JSONObject)qcArray.get(i);
                    Qccxzjlxt.gxinfo tmp =B.new gxinfo();
                    tmp.line_number =s.optString("line_number");
                    tmp.work_station = s.optString("work_station");
                    tmp.worker_id = s.optString("worker_id");
                    tmp.worker_name = s.optString("worker_name");
                    tmp.opera_desc = s.optString("opera_desc");
                    tmp.opera_code =  s.optString("opera_code");
                    tmp.primary_order =  s.optString("Primary_Order");
                    Config.qccxzjlxt.gxinfoArrayList.add(tmp);
                }


                List<ListviewData> listdata = new LinkedList<ListviewData>(); ;
                for(int i = 0 ;i<Config.qccxzjlxt.gxinfoArrayList.size();i++)
                {
                    String name = Config.qccxzjlxt.gxinfoArrayList.get(i).worker_name;
                    String workstatio = Config.qccxzjlxt.gxinfoArrayList.get(i).work_station;
                    String code = Config.qccxzjlxt.gxinfoArrayList.get(i).primary_order;
                    String des = Config.qccxzjlxt.gxinfoArrayList.get(i).opera_desc;

                    String content0 = name + "   " +"工序："+code;
                    ListviewData tmp = new ListviewData(R.mipmap.worker,content0,des);
                    listdata.add(tmp);
                }


                mAdapter = new MyListViewAdapter((LinkedList<ListviewData>) listdata,context);
                listView.setAdapter(mAdapter);

                TextView tv_id = (TextView)view.findViewById(R.id.pd_order_id);
                tv_id.setText(Config.qccxzjlxt.order_id);


                TextView tv_style = (TextView)view.findViewById(R.id.pd_style_id);
                tv_style.setText(Config.qccxzjlxt.style_id);


                TextView tv_order_num = (TextView)view.findViewById(R.id.pd_order_number);
                tv_order_num.setText(Config.qccxzjlxt.order_quantity);

            }
            catch (JSONException je)
            {
                je.printStackTrace();
            }catch (IOException e)
            {
                e.printStackTrace();
            }
        }

        else
        {
            try {
                JSONObject jsonObj = new JSONObject(defaultgylxt);
                jsonObj=null;//暂时不使用
                if(jsonObj==null)
                    return;
                String style_id = jsonObj.optString("style_id");
                String order_id = jsonObj.optString("order_id");
                String style_size = jsonObj.optString("style_size");
                String style_colour = jsonObj.optString("style_colour");
                String Order_Quantity = jsonObj.optString("order_quantity");

                Config.qccxzjlxt.order_id =order_id;
                Config.qccxzjlxt.style_id = style_id;
                Config.qccxzjlxt.order_quantity =Order_Quantity;
                Log.i(TAG,Config.qccxzjlxt.order_id+"-"+Config.qccxzjlxt.style_id+"-"+Config.qccxzjlxt.order_quantity);


                JSONArray qcArray = jsonObj.getJSONArray("data");
                if(qcArray==null)
                    return;

                Qccxzjlxt B = new Qccxzjlxt();
                if(qcArray.length()!=0)
                    Config.qccxzjlxt.gxinfoArrayList.clear();


                for (int i=0;i<qcArray.length();i++)
                {
                    JSONObject s= (JSONObject)qcArray.get(i);
                    Qccxzjlxt.gxinfo tmp =B.new gxinfo();
                    tmp.line_number =s.optString("line_number");
                    tmp.work_station = s.optString("work_station");
                    tmp.worker_id = s.optString("worker_id");
                    tmp.worker_name = s.optString("worker_name");
                    tmp.opera_desc = s.optString("opera_desc");
                    tmp.opera_code =  s.optString("opera_code");
                    tmp.primary_order =  s.optString("Primary_Order");
                    Config.qccxzjlxt.gxinfoArrayList.add(tmp);
                }


                List<ListviewData> listdata = new LinkedList<ListviewData>(); ;
                for(int i = 0 ;i<Config.qccxzjlxt.gxinfoArrayList.size();i++)
                {
                    String name = Config.qccxzjlxt.gxinfoArrayList.get(i).worker_name;
                    String workstatio = Config.qccxzjlxt.gxinfoArrayList.get(i).work_station;
                    String des = Config.qccxzjlxt.gxinfoArrayList.get(i).opera_desc;
                    String code = Config.qccxzjlxt.gxinfoArrayList.get(i).primary_order;
                    String content0 = name + "   " +"工序："+code;
                    ListviewData tmp = new ListviewData(R.mipmap.worker,content0,des);
                    listdata.add(tmp);
                }
                mAdapter = new MyListViewAdapter((LinkedList<ListviewData>) listdata,context);
                listView.setAdapter(mAdapter);

                TextView tv_id = (TextView)view.findViewById(R.id.pd_order_id);
                tv_id.setText(Config.qccxzjlxt.order_id);

                TextView tv_style = (TextView)view.findViewById(R.id.pd_style_id);
                tv_style.setText(Config.qccxzjlxt.style_id);

                TextView tv_order_num = (TextView)view.findViewById(R.id.pd_order_number);
                tv_order_num.setText(Config.qccxzjlxt.order_quantity);
            }
            catch (JSONException je)
            {
                je.printStackTrace();
            }

          //mAdapter = new MyListViewAdapter((LinkedList<ListviewData>) mData,context);
            // listView.setAdapter(mAdapter);
        }*/




        if(mAdapter.getCount()!=0) //default
        {
            mAdapter.setSelectPosition(0);
        }

        //给listview设置item的点击监听
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
            {
                mAdapter.setSelectPosition(position);

            }
        });

    }

    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run()
        {
            if(Config.fragment_index==2)
            {
                /* Message message = new Message();
                message.arg1 = 200;
                handler.sendMessage(message);*/
                if(get_ok==false)
                new MessageToUi().send(200,"","",handler);
                //Log.i(TAG,"主Activity 定时器工作...");
            }
        }
    };

    public void flushproducessinfo(String oederid)
    {
        if(Config.fragment_index==2)
            new MessageToUi().send(200,"","",handler);
    }

    public void initParam()
    {
/*      inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View contentview = inflater.inflate(R.layout.frag_product_qc, null);
        contentview.setFocusable(true);
        contentview.setFocusableInTouchMode(true);
        initContentview(contentview);




        initEditTextEvent(contentview);
        popupWindow = new PopupWindow(contentview, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00005511));
        popupWindow.setBackgroundDrawable(new ColorDrawable());

        myDbHelper = new Db(context,"tps10.db",null,1);*/
    }

    public void initElem()
    {
/*        llShaixuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.showAtLocation(view,  Gravity.RIGHT, 0, 0);
            }
        });*/

    }
    private  Button btn_confirm;
    private  Button btn_reset;
    private String[] ptime = new String[2];
    public void initContentview(View contentview)
    {
/*      btn_confirm = (Button) contentview.findViewById(R.id.btn_confirm);
        btn_reset = (Button) contentview.findViewById(R.id.btn_reset);
        btn_confirm.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view) {
*//*                tableview.setHeader("产生时间", "订单编号","订单款号","款式尺寸/颜色","工序代码","员工姓名");
                tableview.refreshTable();*//*
                boolean ret = queryData(myDbHelper);
                if (!ret)
                showAlertDialog("无记录",0);
            }
        });
        btn_reset.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view) {

                ptime_s.setText("");
                ptime_s.clearFocus();
                ptime_e.setText("");
                ptime_e.clearFocus();

            }
        });*/

    }

    private void showReturnAlterDialog(String msg,final int type)
    {
        AlertDialog returnAlterDialog = new AlertDialog.Builder(context)
                .setIcon(R.mipmap.ic_info)
                .setTitle("注意")
                .setMessage(msg).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
                        try
                        {
                            JSONObject commitdps = new JSONObject();
                            JSONArray faultcodearray = new JSONArray();
                            int k = 0;
                            for (int n = 0; n < duoxuanadapter.faultInfoArrayList.size(); n++)
                            {
                                if (duoxuanadapter.faultInfoArrayList.get(n).clickedList != 0)
                                {
                                    faultcodearray.put(k, duoxuanadapter.faultInfoArrayList.get(n).fault_code);
                                    k++;
                                }
                            }
                            commitdps.put("faultCodeList", faultcodearray);
                            String pathdps = "http://" + Config.devConfig.web_addr + "/pis/defect/addTypeInfo?";
                            String po = "po=" + Config.globalrealorderid;
                            String type = "&typeInfo=" + URLEncoder.encode(commitdps.toString(), "utf-8");

                            String name = "&name="+"";
                            String code = "&code="+Config.RePairCodeString;
                            String qrcode = "&qrCode="+Config.qrcode;
                            String hangerid = "&hangeId="+Config.globalrealhangerid;

                            String ss = po + type + name + code+qrcode+hangerid;
                            String url = pathdps + ss;
                            sendDpsRequestFaultInfo(url);

                            MyToast.showToast(context, "返修数据已提交吊挂，等待吊挂执行,请稍后....");
                            MyMqttClient.qc_repair();
                            mAdapter.map1.clear();
                            mAdapter.notifyDataSetChanged();
                        }
                        catch (Exception e)
                        {


                        }
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
                        dialogInterface.dismiss();
                    }
                }).create();

        returnAlterDialog.getWindow().setDimAmount(0.1f);//设置昏暗度为0
        returnAlterDialog.getWindow().setBackgroundDrawableResource(R.color.color_light_red);


        returnAlterDialog.setCanceledOnTouchOutside(false);
        returnAlterDialog.show();
        //一定要在show的后面
        returnAlterDialog.getButton(AlertDialog.BUTTON_POSITIVE).setWidth(120);
        returnAlterDialog.getButton(AlertDialog.BUTTON_POSITIVE).setHeight(100);
        returnAlterDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextSize(28);

        returnAlterDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setWidth(120);
        returnAlterDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setHeight(100);
        returnAlterDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextSize(28);

        returnAlterDialog.getButton(AlertDialog.BUTTON_POSITIVE).setBackgroundResource(R.color.color_gold);
        returnAlterDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setBackgroundResource(R.color.color_gray0);


    }

    private void showAlertDialog(String msg, final int type) {
        AlertDialog.Builder builder= new AlertDialog.Builder(context);
        builder.setTitle("注意").setMessage(msg);
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
  /*              //ok
                httpGetVerificationInfo thred0 = new httpGetVerificationInfo(handler,context,"");
                thred0.start();*/
                try {

                    int b = 1;/*DPS 返修提交*/
                    if (b == 1) {

                        JSONObject commitdps = new JSONObject();
                        JSONArray faultcodearray = new JSONArray();
                        int k = 0;
                        for (int n = 0; n < duoxuanadapter.faultInfoArrayList.size(); n++)
                        {
                            if (duoxuanadapter.faultInfoArrayList.get(n).clickedList != 0)
                            {
                                faultcodearray.put(k, duoxuanadapter.faultInfoArrayList.get(n).fault_code);
                                k++;
                            }
                        }
                        commitdps.put("faultCodeList", faultcodearray);
                        String pathdps = "http://" + Config.devConfig.web_addr + "/pis/defect/addTypeInfo?";
                        String po = "po=" + Config.globalrealorderid;
                        String type = "&typeInfo=" + URLEncoder.encode(commitdps.toString(), "utf-8");

                 /*     String des = "天顺的跟以前威云的不一样,天顺是多道工序一起返修,威云的是一道";
                        des = URLEncoder.encode(des, "utf-8");
                        String name = "&name="+des;*/
                        String name = "&name="+"";
                        String code = "&code="+Config.RePairCodeString;
                        String qrcode = "&qrCode="+Config.qrcode;
                        String hangerid = "&hangeId="+Config.globalrealhangerid;

              /*        int selection = mAdapter.getSelection();
                        if (selection < Config.qccxzjlxt.gxinfoArrayList.size()&&selection>=0)
                        {
                            name = name + Config.qccxzjlxt.gxinfoArrayList.get(selection).opera_desc;
                            code = code + Config.qccxzjlxt.gxinfoArrayList.get(selection).primary_order;

                            String dpsresult = "";
                            String ss = po + type + name + code;

                            dpsresult = URLEncoder.encode(ss, "utf-8");

                            String url = pathdps + dpsresult;
                            sendDpsRequestFaultInfo(url);
                        }
                        else
                        {
                            Log.i(TAG, "selection err!");

                        }*/
                        String ss = po + type + name + code+qrcode+hangerid;
                        String url = pathdps + ss;
                        sendDpsRequestFaultInfo(url);

                    }//

                    MyToast.showToast(context, "返修数据已提交吊挂，等待吊挂执行,请稍后....");
                    MyMqttClient.qc_repair();
                    mAdapter.map1.clear();
                    mAdapter.notifyDataSetChanged();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                    MyToast.showToast(context,e.toString());
                }

            }


        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //cancle

            }

        });
        builder.show();
    }

    @Override
    public void onStart()
    {
        super.onStart();
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        onDetach = true;
        Log.i(TAG,TAG+"onDestroy ......");
        unbinder.unbind();
    }

    //自定义handler类
    class Gyinfo extends Handler {
        @Override
        //接收别的线程的信息并处理
        public void handleMessage(Message msg) {
            Log.i("GYINFO",Integer.toString(msg.arg1));

            if(onDetach==true)
                return;
            try
            {
            switch (msg.arg1)
            {
                case 1:
                    List<ListviewData> listdata = new LinkedList<ListviewData>();
                    int size = DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.size();
                    Log.i(TAG,"workstation list size:"+size);
                    int sum = 0;

                    for (int i = 0; i < DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.size(); i++) {

                        String workstatio = DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.get(i).workstation;

                        for(int k=0;k<DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.get(i).nameList.size();k++)
                        {
             /*               String des = DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.
                                    get(i).nameList.get(k);*/

                            String des = DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.
                                    get(i).nameJsonLists.get(k).name+"("+DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.
                                    get(i).nameJsonLists.get(k).code+")";
                            String content0 =  "工位："+workstatio;
                            ListviewData tmp = new ListviewData(R.mipmap.worker, content0, des,DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.
                                    get(i).nameJsonLists.get(k).code);
                            listdata.add(tmp);
                            sum ++;
                        }
                    }

                    mAdapter = new MyListViewAdapter((LinkedList<ListviewData>) listdata, context);

                    if(listView!=null)
                            listView.setAdapter(mAdapter);
                        else return;

                        //Toast.makeText(context, "工序列表更新成功！。。", Toast.LENGTH_SHORT).show();
                        //
                        MyToast.showToast(context,"同步了"+sum+"道工序");

                    get_ok = true;

                  break;
                case 2:
                   duoxuanadapter.faultInfoArrayList.clear();
                   for(int i=0;i<Config.faultInfoArrayList.size();i++)
                   {
                      duoxuanadapter.faultInfoArrayList.add(Config.faultInfoArrayList.get(i));
                   }
                   gridview.setAdapter(duoxuanadapter);
                   duoxuanadapter.clear();
                   duoxuanadapter.notifyDataSetChanged();

                   //Toast.makeText(context, "缺陷列表更新成功！。。", Toast.LENGTH_SHORT).show();
                   MyToast.showToast(context,"缺陷列表更新成功！。。");
                   break;
                case 3:

                    String ss = "缺陷列表更新失败: "+msg.obj.toString();

                    MyToast.showToast(context,ss);

                    break;
                case 4:

                    String sss = "缺陷列表更新失败: 网络错误"+msg.obj.toString();
                    Toast.makeText(context, sss, Toast.LENGTH_SHORT).show();
                    break;

                case 10:
                    break;
                case 11:
                    break;
                case 12:
                    break;
                case 13:
                case 14:

                    break;
                case 20:
                {
                    Bundle bundle1=msg.getData();
                    String info = bundle1.getString("exception");
                    MyToast.showToast(context,info);
                }
                break;

                case 22:
                {
                    Bundle bundle1=msg.getData();
                    ChangXianProductNum tmp  = bundle1.getParcelable("ChangXianProductNum");
                    tV_order_finished_num.setText(tmp.orderFinishedNum);
                    tV_order_defect_num.setText(tmp.orderDefectNum);
                    tV_day_finished_num.setText(tmp.dayFinishedNum);
                    tV_day_defect_num.setText(tmp.dayDefectNum);
                   // MyToast.showToast(context,"产量更新成功！");

                    tV_order_finished_num.setInAnimation(InAnimationSet1);
                    tV_order_finished_num.setOutAnimation(OutAnimationSet1);

                    tV_order_defect_num.setInAnimation(InAnimationSet2);
                    tV_order_defect_num.setOutAnimation(OutAnimationSet2);


                    tV_day_finished_num.setInAnimation(InAnimationSet3);
                    tV_day_finished_num.setOutAnimation(OutAnimationSet3);


                    tV_day_defect_num.setInAnimation(InAnimationSet4);
                    tV_day_defect_num.setOutAnimation(OutAnimationSet4);



/*                    duoxuanadapter.faultInfoArrayList.clear();
                    for(int i=0;i<Config.faultInfoArrayList.size();i++)
                    {
                        duoxuanadapter.faultInfoArrayList.add(Config.faultInfoArrayList.get(i));
                    }
                    gridview.setAdapter(duoxuanadapter);
                    duoxuanadapter.clear();
                    duoxuanadapter.notifyDataSetChanged();*/

                }break;
                case 23:
                {
                    Bundle bundle1=msg.getData();
                    String info = bundle1.getString("exception");
                    MyToast.showToast(context,info);
                }break;

                case 200:
                {
                    if(Config.globalrealorderid.length()!=0)
                    {
                        Config A = new Config(context);
                        Config.DpsInterface dpsInterface = A.new DpsInterface(Config.devConfig.web_addr);
                        String url = dpsInterface.changxianqc_comitproduct + "&po=" + Config.globalrealorderid+"&workNum="+Config.rfidWorkerInfo.workernum;
                        sendchangxianqc_comitproduct(url);


                        pd_order_id.setText(Config.globalrealorderid);
                        pd_order_id.setInAnimation(InAnimationSet);
                        pd_order_id.setOutAnimation(OutAnimationSet);


                        pd_style_value.setText(DpsOrderInfo.styNum);
                        pd_style_value.setInAnimation(InAnimationSet5);
                        pd_style_value.setOutAnimation(OutAnimationSet5);

                        pd_order_number_value.setText(Integer.toString(DpsOrderInfo.orderNum));
                        pd_order_number_value.setInAnimation(InAnimationSet6);
                        pd_order_number_value.setOutAnimation(OutAnimationSet6);
                    }
                }
                break;

                case 803:
                {
                    pd_hanger_id_value.setText(Config.globalrealhangerid);
                    pd_hanger_id_value.setInAnimation(InAnimationSet7);
                    pd_hanger_id_value.setOutAnimation(OutAnimationSet7);
                }
                break;
                case 400:
                {
                    Bundle bundle1=msg.getData();
                    String info = bundle1.getString("repairQc");
                    MyToast.showToast(context,info);
                }
                break;

                case 500:
                {
                    Bundle bundle1=msg.getData();
                    String info = bundle1.getString("Verification");
                    MyToast.showToast(context,info);

                    if(rtlcode0==1)
                    {
/*                        //MyToast.showToast(context,"站位鉴权成功:"+key0+"开始提交返修信息:"+Config.RePairCodeString);
                        httpUpdateQcResultV2 thread1 = new httpUpdateQcResultV2
                                (handler,context,"",key0,Config.globalrealhangerid,Config.RePairCodeString);
                        thread1.start();*/
                    }
                    else
                    {
                        //秘钥验证错误
                        MyToast.showToast(context,"站位鉴权错误");
                        return;
                    }

                }
                break;

                case 501:
                {
                    Bundle bundle1=msg.getData();
                    String info = bundle1.getString("UpdateQcResultV2");
                    MyToast.showToast(context,info);

                }
                    break;



                default:
                    break;
            }
        }catch (Exception e)
        {
            e.printStackTrace();
            MyToast.showToast(context,e.toString());
        }
        }
    }


    private void sendRequestFaultInfo(final String url)
    {
        httpCommitFault thread = new httpCommitFault(handler,context,url);
        thread.start();
    }


    public class httpCommitFault extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httpCommitFault(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run()
        {
            Message msg1;
            String result = "";
            int code = -1;
            HttpClient httpCient = new DefaultHttpClient();
            try
            {
                HttpGet httpGet = new HttpGet(Url);


                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {
                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;

                        if(jsonObj.has("result")==true)
                        {
                            Log.i(TAG,"返修成功！！");
                            msg1=handler0.obtainMessage();//每发送一次都要重新获取
                            msg1.arg1 = 11;
                            msg1.obj = code;
                            handler0.sendMessage(msg1);
                        }
                        else
                        {
                            Log.i(TAG,"返修失败！");
                            msg1=handler0.obtainMessage();//每发送一次都要重新获取
                            msg1.arg1 = 12;
                            msg1.obj = code;
                            handler0.sendMessage(msg1);
                        }
                    }
                    catch (JSONException e)
                    {

                        e.printStackTrace();
                    }
                }
                else
                {
                    msg1=handler0.obtainMessage();//每发送一次都要重新获取
                    msg1.arg1 = 13;
                    msg1.obj = code;
                    handler0.sendMessage(msg1);
                }
            }catch (Exception e)
            {
                msg1=handler0.obtainMessage();//每发送一次都要重新获取
                msg1.arg1 = 14;
                msg1.obj = code;
                handler0.sendMessage(msg1);
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                return;
            }
        }

    }


    private void sendDpsRequestFaultInfo(final String url)
    {
        httpDpsCommitFault thread = new httpDpsCommitFault(handler,context,url);
        waitDialog.show();//loading......
        thread.start();
    }


    public class httpDpsCommitFault extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httpDpsCommitFault(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run()
        {
            Message msg1;
            String result = "";
            HttpClient httpCient = new DefaultHttpClient();
            httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,4000);//连接时间
            httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
            try
            {
                HttpGet httpGet = new HttpGet(Url);
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                waitDialog.dismiss();

                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {

                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;

                        if(jsonObj.has("error")==true)
                        {
                            Log.i(TAG,"提交缺陷错误！！");
                            JSONObject error =  jsonObj.optJSONObject("error");
                            String message = error.optString("message");
                            String s = "提交缺陷错误："+message;
                            Bundle bundle = new Bundle();
                            bundle.putString("exception",s);
                            msg1=handler0.obtainMessage();//每发送一次都要重新获取
                            msg1.arg1 = 23;
                            msg1.setData(bundle);
                            handler0.sendMessage(msg1);
                        }
                        else
                        {
                            if(jsonObj.has("data")==true)
                            {
                                JSONObject data = jsonObj.optJSONObject("data");

                                Log.i(TAG, "提交缺陷成功");

                                //订单的完成数，订单缺陷率，今日完成件数，今日缺陷率
                           /*     String orderFi = data.optString("total");//
                                String todaydefectvalue = data.optString("defect");
                                String orderfinshedvalue = data.optString("OrderRegular");
                                String todayratevalue = data.optString("rate");*/

                              /*  刷新界面*/
                      /*          File dpsProuductIndotxt = new File(Config.dpsProuductIndotxt);
                                OutputStream os = new FileOutputStream(dpsProuductIndotxt);
                                byte b[] = jsonObj.toString().getBytes("UTF-8");
                                os.write(b);
                                os.close();*/


                                ChangXianProductNum tmp = new ChangXianProductNum();
                                tmp.orderFinishedNum = Integer.toString(data.optInt("OrderRegular"));
                                tmp.orderDefectNum = Integer.toString(data.optInt("OrderDefect"));
                                tmp.dayFinishedNum = Integer.toString(data.optInt("regular"));
                                tmp.dayDefectNum = Integer.toString(data.optInt("defect"));

                                Bundle bundle = new Bundle();
                                bundle.putParcelable("ChangXianProductNum",tmp);
                                msg1=handler0.obtainMessage();//每发送一次都要重新获取
                                msg1.arg1 = 22;
                                msg1.setData(bundle);
                                handler0.sendMessage(msg1);
                            }

                        }
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();

                        Bundle bundle = new Bundle();
                        bundle.putString("exception",e.toString());
                        msg1=handler0.obtainMessage();//每发送一次都要重新获取
                        msg1.arg1 = 23;
                        msg1.setData(bundle);
                        handler0.sendMessage(msg1);
                    }
                }
                else
                {
                    Log.i(TAG,"服务端返回："+Integer.toString(code));

                    Bundle bundle = new Bundle();
                    bundle.putString("exception","服务端返回："+Integer.toString(code));
                    msg1=handler0.obtainMessage();//每发送一次都要重新获取
                    msg1.arg1 = 23;
                    msg1.setData(bundle);
                    handler0.sendMessage(msg1);

                }
            }catch (Exception e)
            {

                Log.e(TAG, "HTTP request err......");
                waitDialog.dismiss();
                e.printStackTrace();
                Bundle bundle = new Bundle();
                bundle.putString("exception",e.toString());
                msg1=handler0.obtainMessage();//每发送一次都要重新获取
                msg1.arg1 = 23;
                msg1.setData(bundle);
                handler0.sendMessage(msg1);

            }

        }

    }




    private class GetDataTask extends AsyncTask<Void, Void, String[]> {

        @Override
        protected String[] doInBackground(Void... params) {
            // Simulates a background job.
            try {
                Thread.sleep(800);
            } catch (InterruptedException e)
            {
            }
            return null;
        }

        @Override
        protected void onPostExecute(String[] result) {
/*            mListItems.addFirst("Added after refresh...");
            mListItems.addAll(Arrays.asList(result));*/

/*       ITS     String url = "http://" + Config.devConfig.web_addr + "/js/a/its/terminal/faultInfo?";
            sendRequestDefect(url);*/
           // duoxuanadapter.faultInfoArrayList.clear();
           // gridview.setAdapter(duoxuanadapter);
           // duoxuanadapter.notifyDataSetChanged();


            gridview.onRefreshComplete();
            super.onPostExecute(result);
        }
    }

    public void sendPostVerificationLogon()
    {






    }


    public void sendRequestDefect(String url)
    {
        httpgetdefect thread = new httpgetdefect(handler,context,url);
        thread.start();
    }

    public class httpgetdefect extends Thread
    {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public httpgetdefect(Handler handlerin, Context contextin, String url)
        {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run()
        {
            Message msg1;
            String result = "";
            HttpClient httpCient = new DefaultHttpClient();

            httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,3000);//连接时间
            httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间

            try
            {
                HttpGet httpGet = new HttpGet(Url);
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {
                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;

                        if(jsonObj.has("result")==true)
                        {
                            Log.i(TAG,"获取缺陷成功！");
                            JSONArray qcArray = jsonObj.optJSONArray("data");
                            if(qcArray==null) {
                                new MessageToUi().send(20,"exception","缺陷数据为空",handler0);
                                return;
                            }
                            if(qcArray.length()!=0)
                                Config.faultInfoArrayList.clear();
                            for (int i=0;i<qcArray.length();i++)
                            {
                                JSONObject s= (JSONObject)qcArray.opt(i);
                                FaultInfo tmp = new FaultInfo();
                                tmp.fault_name =s.optString("fault_name");
                                tmp.fault_code = s.optString("fault_code");
                                tmp.clickedList = 0;
                                Config.faultInfoArrayList.add(tmp);
                            }
                            File gylxt = new File(Config.faultinfotxt);
                            OutputStream os = new FileOutputStream(gylxt);
                            byte b[] = jsonObj.toString().getBytes("UTF-8");
                            os.write(b);
                            os.close();
                            msg1=handler0.obtainMessage();//每发送一次都要重新获取
                            msg1.arg1 = 2;
                            msg1.obj = code;
                            handler0.sendMessage(msg1);
                        }
                        if(jsonObj.has("data")==true)
                        {
                            Log.i(TAG,"获取缺陷成功！");
                            JSONArray qcArray = jsonObj.optJSONArray("data");
                            if(qcArray==null)
                                return;
                            if(qcArray.length()!=0)
                                Config.faultInfoArrayList.clear();
                            for (int i=0;i<qcArray.length();i++)
                            {
                                JSONObject s= (JSONObject)qcArray.get(i);
                                FaultInfo tmp = new FaultInfo();
                                tmp.fault_name =s.optString("name");
                                tmp.fault_code = s.optString("type");
                                tmp.category_name = s.optString("categoryName");
                                tmp.clickedList = 0;
                                Config.faultInfoArrayList.add(tmp);
                            }

                            new MessageToUi().send(2,"faultinfoget","获取缺陷成功",handler0);
                            File gylxt = new File(Config.faultinfotxt);
                            OutputStream os = new FileOutputStream(gylxt);
                            byte b[] = jsonObj.toString().getBytes("UTF-8");
                            os.write(b);
                            os.close();

                        }
                        else if(jsonObj.has("error")==true)
                        {
                            JSONObject error = jsonObj.optJSONObject("error");
                            String message = error.optString("message");
                            new MessageToUi().send(20,"exception",message,handler0);
                        }
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        new MessageToUi().send(20,"exception",e.toString(),handler0);
                    }
                }
                else
                {
                    Log.i(TAG,"获取缺陷失败1！");
                    new MessageToUi().send(20,"exception","获取缺陷失败,服务端返回："+Integer.toString(code),handler0);
                }

            }catch (Exception e)
            {
                e.printStackTrace();
                new MessageToUi().send(20,"exception",e.toString(),handler0);

            }
        }
    }

    public void  sendchangxianqc_comitproduct(String url)
    {
        if(Config.qrCodeInfo.location.length()!=6)
        {
            MyToast.showToast(context,"设备二维码信息未绑定或绑定错误？");
            return;
        }
        if(Config.rfidWorkerInfo.workernum.length()==0)
        {
            MyToast.showToast(context,"请先刷卡登录?");
            return;
        }


        changxianqc_comitproduct thread = new changxianqc_comitproduct(handler,context,url);
        thread.start();
    }

    public class changxianqc_comitproduct extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;

        public changxianqc_comitproduct(Handler handlerin, Context contextin, String url)
        {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
        }
        public void run()
        {
            Message msg1;
            String result = "";
            HttpClient httpCient = new DefaultHttpClient();

            httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5000);//连接时间
            httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,4000);//数据传输时间
            try {

                HttpGet httpGet = new HttpGet(Url);
                int code = -1;

                Log.i(TAG, Url);
                HttpResponse response = httpCient.execute(httpGet);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "get call reponse code: "+Integer.toString(code));
                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity = response.getEntity();
                    result = EntityUtils.toString(entity, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {
                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;
                        if(jsonObj.has("error")==true)
                        {
                            JSONObject error =  jsonObj.optJSONObject("error");
                            Log.i(TAG,"获取产量错误！！");
                            String message = error.optString("message");
                            String s = "获取产量和工艺路线图错误："+message;
                           //String s = "工序返修成功！";
                            new MessageToUi().send(23,"exception",s,handler0);
                        }
                        else
                        {
                            JSONObject data =  jsonObj.optJSONObject("data");
                            Log.i(TAG,"获取产量成功。。！！");
                            if(data!=null)
                            {
                                JSONArray array0 = data.optJSONArray("stationInfo");
                                if(array0!=null)
                                {
                                    int size = array0.length();
                                    if(size<0)
                                    {
                                        String err  ="请至少提供一道工序！";
                                        new MessageToUi().send(23,"exception",err,handler0);
                                    }
                                    else
                                    {
                                        //服务端推送5秒，刷新界面太快，使用缓存判断
                                        String stationInfo = array0.toString();
                                        if(stationInfo.compareTo(LastProcessLineCache)!=0)
                                        {

                                            LastProcessLineCache = stationInfo;
                                           // Log.e(TAG,LastProcessLineCache);


                                            DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.clear();
                                            for (int i = 0; i < size; i++) {
                                                JSONObject obj0 = array0.optJSONObject(i);
                                                String station = obj0.optString("station");

                                                IcMesOrderProcessRouteMapInfo.WorkSationProcessInfo tmp = new IcMesOrderProcessRouteMapInfo().new WorkSationProcessInfo();
                                                tmp.workstation = station;

                                                JSONArray array1 = array0.optJSONObject(i).optJSONArray("nameList");
                                                int num = array1.length();
                                                //num  = 0; //不解析了
                                                for (int k = 0; k < num; k++) {
                                                    String des = array1.optString(k);
                                                    tmp.nameList.add(des);
                                                }

                                                JSONArray array2 = array0.optJSONObject(i).optJSONArray("nameJsonList");
                                                num = array2.length();

                                                for (int k = 0; k < num; k++) {
                                                    JSONObject t = array2.optJSONObject(k);
                                                    //String desID = Integer.toString(t.optInt("code"));
                                                    String desID =t.optString("code");
                                                    String name = t.optString("name");
                                                    IcMesOrderProcessRouteMapInfo.NameJsonList var = new IcMesOrderProcessRouteMapInfo().new NameJsonList();
                                                    var.code = desID;
                                                    var.name = name;
                                                    tmp.nameJsonLists.add(var);
                                                }
                                                DpsOrderInfo.icMesOrderProcessRouteMapInfo.typeSizeNameInfo.add(tmp);
                                            }
                                            new MessageToUi().send(1, "info", "", handler0);
                                        }
                                    }
                                }
/*                                "defect": 0, //当前产线缺陷数目
                                    "total": 1, //当前产线合格数
                                    "OrderRate": 100,//当前订单合格率
                                    "OrderRegular": 1,//当前订单合格数
                                    "rate": 100,//当前产线合格率
                                    "OrderDefect": 0,//当前订单缺陷数
                                    "type": 1,//忽略
                                    "OrderTotal": 1,//当前订单合格数
                                    "regular": 1 ////当前产线合格数*/

           /*                     String todaytotalvalue=data.optString("total");
                                String todaydefectvalue=data.optString("defect");
                                String orderfinshedvalue=data.optString("OrderRegular");
                                String todayratevalue=data.optString("rate");*/


                                String s = "获取产量成功";
                                ChangXianProductNum tmp = new ChangXianProductNum();
                                tmp.orderFinishedNum = Integer.toString(data.optInt("OrderRegular"));
                                tmp.orderDefectNum = Integer.toString(data.optInt("OrderDefect"));
                                tmp.dayFinishedNum = Integer.toString(data.optInt("regular"));
                                tmp.dayDefectNum = Integer.toString(data.optInt("defect"));

/*
                                DpsOrderInfo.icMesOrderProcessRouteMapInfo.LineDefectNum = todaydefectvalue;
                                DpsOrderInfo.icMesOrderProcessRouteMapInfo.LineQualifiedRate = todayratevalue;
                                DpsOrderInfo.icMesOrderProcessRouteMapInfo.OrderQualifiedNum = orderfinshedvalue;
*/

                                /*

 */
                    /*          *//*  刷新界面*//*
                                File dpsProuductIndotxt = new File(Config.dpsProuductIndotxt);
                                OutputStream os = new FileOutputStream(dpsProuductIndotxt);
                                byte b[] = jsonObj.toString().getBytes("UTF-8");
                                os.write(b);
                                os.close();*/



                                Bundle bundle = new Bundle();
                                bundle.putParcelable("ChangXianProductNum",tmp);
                                msg1=handler0.obtainMessage();//每发送一次都要重新获取
                                msg1.arg1 = 22;
                                msg1.setData(bundle);
                                handler0.sendMessage(msg1);
                            }
                        }
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        Bundle bundle = new Bundle();
                        bundle.putString("exception",e.toString());
                        msg1=handler0.obtainMessage();//每发送一次都要重新获取
                        msg1.arg1 = 23;
                        msg1.setData(bundle);
                        handler0.sendMessage(msg1);
                    }
                }
                else
                {
                    Log.i(TAG,"提交产量,服务端返回："+Integer.toString(code));
                    Bundle bundle = new Bundle();
                    bundle.putString("exception","提交产量,服务端返回："+Integer.toString(code));
                    msg1=handler0.obtainMessage();//每发送一次都要重新获取
                    msg1.arg1 = 23;
                    msg1.setData(bundle);
                    handler0.sendMessage(msg1);
                }

            }catch (Exception e)
            {
                e.printStackTrace();
                //Toast.makeText(context, e.toString(), Toast.LENGTH_SHORT).show();
                Bundle bundle = new Bundle();
                bundle.putString("exception",e.toString());
                msg1=handler0.obtainMessage();//每发送一次都要重新获取
                msg1.arg1 = 23;
                msg1.setData(bundle);
                handler0.sendMessage(msg1);
            }
        }

    }

    public class httpGetVerificationInfo extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;
        public String key = null;
        public int rltcode;

        public httpGetVerificationInfo(Handler handlerin, Context contextin, String url) {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;
            key = "";
            rltcode = 0;
            key0 = "";
            rtlcode0 = 0;

        }
        public void run()
        {
            String url = "http://" + Config.devConfig.addr+":85" + "/StTablet/Verification/Login";

            String result = "";
            HttpClient httpCient = new DefaultHttpClient();
            try
            {
                httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,4000);//连接时间
                httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间
                HttpPost httppost = new HttpPost(url);
                int code = -1;

                Log.i(TAG, url);
                // 构造消息头
                httppost.setHeader("Content-type", "application/json");


                if(Config.qrCodeInfo.location.length()==6)
                {
                    JSONObject obj = new JSONObject();
                    String workline = Config.qrCodeInfo.location.substring(0,4);
                    int stNo = Integer.parseInt(Config.qrCodeInfo.location.substring(4,6));
                    obj.put("workLine",workline);
                    obj.put("stNo",stNo);
                    obj.put("password","qwert");

                    // 构建消息实体
                    StringEntity entity = new StringEntity(obj.toString(), HTTP.UTF_8);
                    entity.setContentEncoding("UTF-8");
                    // 发送Json格式的数据请求
                    entity.setContentType("application/json");
                    httppost.setEntity(entity);

                    Log.i(TAG,"request parameters" + EntityUtils.toString(httppost.getEntity()));
                    Log.i(TAG,"httpPost:" + httppost);
                }

                HttpResponse response = httpCient.execute(httppost);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "post reponse code:"+Integer.toString(code));

                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity0 = response.getEntity();
                    result = EntityUtils.toString(entity0, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {

                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;
                        int rlt = jsonObj.optInt("rlt");
                        String message = jsonObj.optString("msg");
                        rltcode = rlt;

                        rtlcode0 = rltcode;



                        if(rlt==1)
                        {
                            key = message;
                           // key0 = key;
                            String message1 ="鉴权成功返回:"+rlt +"# key="+key;
                            new MessageToUi().send(500,"Verification",message1,handler0);
                            sleep(2000);

                            httpUpdateQcResultV2 thread1 = new httpUpdateQcResultV2
                                    (handler,context,"null ",key,Config.globalrealhangerid,Config.RePairCodeString);
                            thread1.start();
                        }
                        else
                        {

                            new MessageToUi().send(23,"exception",message,handler0);
                            return;
                        }

                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        new MessageToUi().send(23,"exception",e.toString(),handler0);
                    }
                }
                else
                {
                    Log.i(TAG,"服务端返回："+Integer.toString(code));
                    new MessageToUi().send(23,"exception","服务端返回："+Integer.toString(code),handler0);

                }
            }
            catch (JSONException t)
            {
                t.printStackTrace();
            }

            catch (Exception e)
            {
                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
            }
        }
    }



    public class httpUpdateQcResultV2 extends Thread {
        public Context context0 = null;
        public Handler handler0 = null;
        public String Url = null;
        public String key = null;
        public String hangerId =null;
        public String repairStr = null;
        public int rltcode;

        public httpUpdateQcResultV2(Handler handlerin, Context contextin, String url,
                                    String keys,String hangerIds,String repairStrs)
        {
            handler0 = handlerin;
            context0 = contextin;
            Url = url;

            key = keys;
            hangerId = hangerIds;
            repairStr = repairStrs;
            rltcode=0;
            rtlcode1 = 0;

        }
        public void run()
        {
            try
            {
           // sleep(2000);
            String url = "http://" + Config.devConfig.addr+":85" + "/StTablet/QC/UpdateQcResultV2";

            String result = "";
            HttpClient httpCient = new DefaultHttpClient();
            httpCient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,2000);//连接时间
            httpCient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间

            HttpPost httppost = new HttpPost(url);

            int code = -1;

                Log.i(TAG, url);
                // 构造消息头
                httppost.setHeader("Content-type", "application/json");
                JSONObject obj = new JSONObject();
                obj.put("cardNo",Integer.parseInt(hangerId));
                obj.put("qcPass",false);
                obj.put("failQty",1);
                obj.put("failInfo",repairStr);
                obj.put("userid",key);

                    // 构建消息实体
                StringEntity entity = new StringEntity(obj.toString(), HTTP.UTF_8);
                entity.setContentEncoding("UTF-8");
                entity.setContentType("application/json");
                httppost.setEntity(entity);




                Log.i(TAG,"request parameters" + EntityUtils.toString(httppost.getEntity()));
                Log.i(TAG,"httpPost:" + httppost);


                HttpResponse response = httpCient.execute(httppost);
                code = response.getStatusLine().getStatusCode();
                Log.i(TAG, "post reponse code:"+Integer.toString(code));

                if (response.getStatusLine().getStatusCode() == 200)
                {
                    HttpEntity entity0 = response.getEntity();
                    result = EntityUtils.toString(entity0, HTTP.UTF_8);
                    Log.i(TAG, result);
                    try {

                        JSONObject jsonObj = new JSONObject(result);
                        if (jsonObj == null)
                            return;
                        int rlt = jsonObj.optInt("rlt");
                        String message = jsonObj.optString("msg");

                        rltcode = rlt;
                        rtlcode1 = rltcode;

                       String message1 ="返修提交"+"秘钥:"+key+"# 后台返回:"+rlt +"#"+message ;

                       if(rlt==1)
                       {
                            new MessageToUi().send(400,"repairQc",message1,handler0);
                       }
                       else
                       {
                            new MessageToUi().send(501,"UpdateQcResultV2",message1,handler0);
                            //new MessageToUi().send(23,"exception",message,handler0);
                            return;
                       }
                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                        new MessageToUi().send(23,"exception",e.toString(),handler0);
                    }
                }
                else
                {
                    Log.i(TAG,"服务端返回："+Integer.toString(code));
                    new MessageToUi().send(23,"exception","服务端返回："+Integer.toString(code),handler0);

                }
            }
            catch (JSONException t)
            {
                t.printStackTrace();
                new MessageToUi().send(23,"exception",t.toString(),handler0);

            }

            catch (Exception e)
            {

                Log.e(TAG, "HTTP request err......");
                e.printStackTrace();
                new MessageToUi().send(23,"exception",e.toString(),handler0);
            }

        }

    }



    public void httpquestVerificationLogon()
    {
        String result = "";
        HttpClient httpCient = new DefaultHttpClient();
        String url = "http://" + Config.devConfig.web_addr+":85" + "/StTablet/Verification/Login?";
        HttpGet httpGet = new HttpGet(url);
        int code = -1;
        try {
            Log.i(TAG, url);
            HttpResponse response = httpCient.execute(httpGet);
            code = response.getStatusLine().getStatusCode();
            Log.i(TAG, "get call reponse code: "+Integer.toString(code));
            if (response.getStatusLine().getStatusCode() == 200)
            {
                HttpEntity entity = response.getEntity();
                result = EntityUtils.toString(entity, HTTP.UTF_8);
                Log.i(TAG, result);
                try {
                    JSONObject jsonObj = new JSONObject(result);
                    if (jsonObj == null)
                        return;

                    if(jsonObj.has("result")==true)
                    {
                        Log.i(TAG,"获取缺陷成功！");
                        JSONArray qcArray = jsonObj.getJSONArray("data");
                        if(qcArray==null)
                            return;
                        if(qcArray.length()!=0)
                            Config.faultInfoArrayList.clear();
                        for (int i=0;i<qcArray.length();i++)
                        {
                            JSONObject s= (JSONObject)qcArray.get(i);
                            FaultInfo tmp = new FaultInfo();
                            tmp.fault_name =s.optString("fault_name");
                            tmp.fault_code = s.optString("fault_code");
                            tmp.clickedList = 0;
                            Config.faultInfoArrayList.add(tmp);
                        }
                        File gylxt = new File(Config.faultinfotxt);
                        OutputStream os = new FileOutputStream(gylxt);
                        byte b[] = jsonObj.toString().getBytes("UTF-8");
                        os.write(b);
                        os.close();

                        duoxuanadapter.faultInfoArrayList.clear();
                        for(int i=0;i<Config.faultInfoArrayList.size();i++)
                        {
                            duoxuanadapter.faultInfoArrayList.add(Config.faultInfoArrayList.get(i));
                        }
                        gridview.setAdapter(duoxuanadapter);
                        duoxuanadapter.clear();
                        duoxuanadapter.notifyDataSetChanged();
                        Toast.makeText(context, "获取缺陷信息成功!", Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        String errmessage = jsonObj.optString("message");
                        Log.i(TAG,errmessage);
                        Toast.makeText(context, errmessage, Toast.LENGTH_SHORT).show();
                    }
                }
                catch (JSONException e)
                {
                    e.printStackTrace();
                }
            }
            else
            {
                String err = "获取缺陷错误:"+Integer.toString(code);
                Log.i(TAG,err);
                Toast.makeText(context, err, Toast.LENGTH_SHORT).show();
            }

        }catch (Exception e)
        {
            Log.e(TAG, "HTTP request err......");
            e.printStackTrace();
            return;
        }
    }
}
